package com.ham.mud.races;

import com.ham.mud.Colors;
import com.ham.mud.ServerConnection;
import com.ham.mud.characters.Stats;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by hlucas on Jul 15, 2011 at 10:24:31 AM
 */
public class RaceService {
    private static final List<Race> races = new ArrayList<Race>();

    static {
        races.add(new Drow());
        races.add(new Dwarf());
        races.add(new Elf());
        races.add(new Fairy());
        races.add(new Halfling());
        races.add(new Human());
        races.add(new Ogre());
        races.add(new Orc());
        races.add(new WoodElf());
    }

    public static Race getRace(String raceName) {
        raceName = raceName.toLowerCase();
        for(Race race : races) {
            if(race.getName().toLowerCase().equals(raceName)) {
                try {
                    return race.getClass().newInstance();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }

    public static void showRaces(ServerConnection connection) {
        connection.println();
        connection.println("Races:");
        connection.println("-----------------------------------------");
        connection.println(Colors.getValueAndSpaces(15, "Race") + "| " + "Str Dex Con Int Wis Cha");
        connection.println("-----------------------------------------");

        for(Race race : races) {
            String name = race.getName();
            Stats stats = race.getStats();

            String nameSpace = Colors.getValueAndSpaces(15, name);
            String intSpace =  Colors.getValueAndSpaces(3, String.valueOf(stats.getIntelligence() - 15), true);
            String strSpace =  Colors.getValueAndSpaces(3, String.valueOf(stats.getStrength() - 15), true);
            String conSpace =  Colors.getValueAndSpaces(3, String.valueOf(stats.getConstitution() - 15), true);
            String dexSpace =  Colors.getValueAndSpaces(3, String.valueOf(stats.getDexterity() - 15), true);
            String chaSpace =  Colors.getValueAndSpaces(3, String.valueOf(stats.getCharisma() - 15), true);
            String wisSpace =  Colors.getValueAndSpaces(3, String.valueOf(stats.getWisdom() - 15), true);

            connection.println(nameSpace + "| " + strSpace + " " + dexSpace + " " + conSpace + " " + intSpace + " " + wisSpace + " " + chaSpace);
        }

        connection.println("-----------------------------------------");
    }
}
